package model

import (
	"github.com/doujunyu/gogo/sql_aid"
)

const TableByShop = "self_shop"

const ShopByStatusNormal = 1 //正常
const ShopByStatusForbid = 2 //禁用

// UserIdToShopId 根据用户ID找店铺ID
func UserIdToShopId(userId int64) int64 {
	findShop, args := sql_aid.PgTable(TableByShop).Where("user_id = ?", userId).ToSql()
	findShopData, err := sql_aid.DataToMap(PgSql.Query(findShop, args...))
	if err != nil || len(findShopData) == 0 {
		return 0
	}
	return findShopData[0]["id"].(int64)
}

// ShopByFind 查找单条数据
func ShopByFind(userId int64) ([]map[string]interface{}, error) {
	findShop, args := sql_aid.PgTable(TableByShop).Where("user_id = ?", userId).ToSql()
	findShopData, err := sql_aid.DataToMap(PgSql.Query(findShop, args...))
	if err != nil {
		return nil, err
	}
	return findShopData, nil
}
